//q5.cpp
//This program takes a user ID and print the control digit
//
//Binyamin 28 december 2017
//===========================================================================
#include<iostream>

using namespace std;

//1. prompt the user for the ID without the control digit.
//2. store the ID.
//3. calculate the control digit.
//4. print the ID with the control digit.

int main()
{
	int id, id_c, digit, multi; // id - id as insereted by the user.
				    // id_c - id copy, to manipulate without harming user input.
				    // digit - the current digit when scrolled through the loop.
				    // multi - the current multiplier for each digit.
	int ctrl_m; // ctrl_m - calculation of the control digit.

	cout << "Please enter your ID without the control digit" << endl;
	cin >> id;
	id_c = id;
	ctrl_m=0;
	multi = 2;
	while(id_c >0)
	{
		digit=id_c%10;
		if((multi * digit) >= 10)
		{
			ctrl_m += (multi*digit)/10 + (multi*digit)%10;
		}
		else
			ctrl_m += (multi*digit);
		multi = multi%2 + 1;
		id_c = id_c/10;
		
	}
	cout << "The id is " << id << (ctrl_m/10 + 1)*10 - ctrl_m << endl;

	return 0;
}
//output
//Please enter your ID without the control digit 20324913
//The id is 203249131
